package com.lizhi.handler;

import com.lizhi.exception.TaskException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(TaskException.class)
    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    public String catchTaskException(TaskException ex) {
        return ex.getErrMessage();
    }

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String catchException(Exception ex) {
        ex.printStackTrace();
        return ex.getMessage();
    }
}
